package com.uade.wcf.backend.domain.resources;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.ext.json.JsonRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;

import com.uade.wcg.backend.domain.Player;

public class PlayerResource extends ServerResource{
	
	String lastName;

    //Object user;
	Player player;

	@Get("json")
	public String handleGet() {
	try {
		this.lastName = (String) getRequestAttributes().get("playerLastName");
	    
		//get the player from the model
		this.player = new Player("Ramon", lastName);
		
	    JSONObject json = new JSONObject();
		json.put("name", player.getLastName()); 
	
		JsonRepresentation jsonRep = new JsonRepresentation(json);
	
		return jsonRep.getText();
	} catch (JSONException e) {
		e.printStackTrace();
	} catch (IOException e)
	{
		e.printStackTrace();
	}
	return null;
	}

}
